﻿using System;
using System.IO;

class ConcatenationOfTwoTextFiles
{
    static void Main()
    {
        //Exercise 2.
        //Write a program that concatenates two text files into another text file.
        
        string fileNameOne = @"C:\Users\Toni\Desktop\Test File.txt";
        StreamReader readerOne = new StreamReader(fileNameOne);
        string fileNameTwo = @"C:\Users\Toni\Desktop\Test File_2.txt";
        StreamReader readerTwo = new StreamReader(fileNameTwo);

        string fileNameFinal = "File.txt";
        StreamWriter streamWriter = new StreamWriter(fileNameFinal);

        string final = string.Empty;
        using (readerOne)               //reading the first file
        {
            final = readerOne.ReadToEnd();
        }        
        using (readerTwo)               //reading the second file and append the text at the end
        {
            final = final + readerTwo.ReadToEnd();
        }

        using (streamWriter)            //writing the concatenated text in a new text-file
        {
            streamWriter.Write(final);
        }

        Console.WriteLine("File is written!");
    }
}

